<!--
* @description:添加通用合同管理
* @fileName: NewGeneralContract
* @author:石锦涛
* @date:2022-01-08
* @后台人员:石锦涛
-->
<template>
  <div>
    <!-- 新增通用合同 -->
    <div>
      <el-row :span="1">
        <el-col :span="3">合同标题:</el-col>
        <el-col :span="7"
          ><el-input v-model="jieshu.Thecontracttitles"></el-input
        ></el-col>
        <el-col :span="3">对方单位:</el-col>
        <el-col :span="7"
          ><el-input v-model="jieshu.TheOtherUnits"></el-input
        ></el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">对方负责人:</el-col>
        <el-col :span="7"
          ><el-input v-model="jieshu.TheOtherPartyHead"></el-input
        ></el-col>
        <el-col :span="3">合同类别:</el-col>
        <el-col :span="7">
          <el-input v-model="jieshu.ContractCategory"></el-input>
        </el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">签订时间:</el-col>
        <el-col :span="7"
          ><el-input type="date" v-model="jieshu.SignedTimes"></el-input
        ></el-col>
        <el-col :span="3">经办人:</el-col>
        <el-col :span="7"><el-input v-model="jieshu.Agents"></el-input></el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">合同金额:</el-col>
        <el-col :span="7"
          ><el-input v-model="jieshu.ContractAmounts"></el-input
        ></el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">合同标的或项目说明:</el-col>
        <el-col :span="12"
          ><el-input
            type="textarea"
            :rows="5"
            placeholder="请输入内容"
            v-model="jieshu.ProjectDescriptios"
          >
          </el-input
        ></el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">合同主要条款/变更条款:</el-col>
        <el-col :span="12"
          ><el-input
            type="textarea"
            :rows="5"
            placeholder="请输入内容"
            v-model="jieshu.ThisMainClauses"
          >
          </el-input
        ></el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3">合同文本(附件):</el-col>
        <el-col :span="12">
          <el-upload
            class="upload-demo"
            :on-success="upchuan"
            action="https://localhost:44399/api/app/file-common-app/uplosdqiniu"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">
              
            </div>
          </el-upload>
        </el-col>
      </el-row>
      <br />
      <el-row :span="1">
        <el-col :span="3"><el-button @click="Ti()">提交审批</el-button></el-col>
        <el-col :span="1"><el-button @click="fanhui()">取消</el-button></el-col>
        <el-col :span="3"
          ><el-button @click="addjiashu()">保存草稿</el-button></el-col
        >
      </el-row>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      jieshu: {
        GeneralContractNos: "",
        Thecontracttitles: "",
        TheOtherUnits: "",
        TheOtherPartyHead: "",
        ContractCategory: "",
        ContractAmounts: "",
        Agents: "",
        SignedTimes: "",
        TheContractAmount: "11",
        ProjectDescriptios: "",
        ThisMainClauses: "",
        ContractTexts: "-",
        ContractStatess: "0",
        TheApprovers: "-",
        IsDelete: "0",
      },
    };
  },
  methods: {
    //添加草稿
    addjiashu() {
      if (this.jieshu.Thecontracttitles.length === 0) {
        alert("标题不能为空");
        return;
      }
      if (this.jieshu.TheOtherUnits.length === 0) {
        alert("对方单位不能为空");
        return;
      }
      if (this.jieshu.TheOtherPartyHead.length === 0) {
        alert("对方负责人不能为空");
        return;
      }
      if (this.jieshu.ContractCategory.length === 0) {
        alert("合同类别不能为空");
        return;
      }
      if (this.jieshu.SignedTimes.length === 0) {
        alert("签订时间不能为空");
        return;
      }
      if (this.jieshu.Agents.length === 0) {
        alert("经办人不能为空");
        return;
      }
      if (this.jieshu.ContractAmounts.length === 0) {
        alert("合同金额不能为空");
        return;
      }
      var retNum = /^\d+(\.\d+)?$/; //匹配数字匹配数字(包括小数)/^\d*$/
      if (!retNum.test(this.jieshu.ContractAmounts)) {
        alert("合同金额只能是正数,整数,小数");
        return;
      }
      if (this.jieshu.ProjectDescriptios.length === 0) {
        alert("合同标的或项目说明不能为空");
        return;
      }
      if (this.jieshu.ThisMainClauses.length === 0) {
        alert("合同主要条款/变更条款不能为空");
        return;
      }
      this.$axios
        .post(
          "https://localhost:44399/api/app/new-gener-app/general",
          this.jieshu
        )
        .then((res) => {
          if (res.data.Code > 0) {
            alert("添加成功");
            this.$router.push("/GeneralContractManagement");
          } else {
            alert("添加失败");
          }
        });
    },
    //上传
    upchuan(res) {
      if (res != null) {
        this.$message.success("上传文件成功");
        this.jieshu.ContractTexts = res;
      } else {
        this.$message.success("上传文件失败");
      }
    },
     Ti(){
      let loginid=sessionStorage.getItem("Id");
      let loginname=sessionStorage.getItem("Account");
      this.$axios.post("https://localhost:44399/api/app/general-contract-shen/add-general-contract?loginname="+loginname+"&loginid="+loginid+"",this.jieshu).then(res=>{
        if(res.data>0)
        {
          this.$message.success("提交成功");
        }
        else
        {
          this.$message.error("提交失败");
        }
      })
    },
    //返回管理
    fanhui() {
      this.$router.push("/GeneralContractManagement");
    },
  },
  created() {},
};
</script>

<style>
</style>